{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4b5a90a5",
   "metadata": {
    "tags": []
   },
   "source": [
    "# 引言\n",
    "通过初级教程的学习，我们已经了解了MindSpore开发的基本流程，即：\n",
    "- 加载数据集\n",
    "- 定义超参\n",
    "- 定义网络模型\n",
    "- 定义损失函数\n",
    "- 定义优化器\n",
    "- 训练模型\n",
    "- 保存与导出\n",
    "- 推理与部署"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e9c26490",
   "metadata": {},
   "outputs": [],
   "source": [
    "import mindspore as ms\n",
    "import mindspore.nn as nn\n",
    "from mindspore import ops"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27c342b9",
   "metadata": {},
   "source": [
    "在初级教程中，我们使用的是已经封装好的高阶API，比如当我们需要定义损失函数时，我们可以直接调用mindspore.nn中已经定义好的损失函数："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "18d094f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "lossfunction = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7dbfbe97",
   "metadata": {},
   "source": [
    "而在进阶教程中，我们将学习使用MindSpore中的中低阶API，使用其自定义损失函数、优化器、网络模型等。使用中低阶API自定义损失函数如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "217ad4a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "class MyLossfunction(nn.LossBase):\n",
    "    \"\"\"定义损失函数\"\"\"\n",
    "    def __init__(self):\n",
    "        super(MyLossfunction, self).__init__()\n",
    "        self.abs = ops.Abs()\n",
    "\n",
    "    def construct(self, predict, target):\n",
    "        x = self.abs(target - predict)\n",
    "        return self.get_loss(x)\n",
    "\n",
    "# MindSpore是函数式编程"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f98ead3a",
   "metadata": {},
   "source": [
    "MindSpore的层次结构如下：\n",
    "![](./MindSpore中的API.png)\n",
    "接下来，我们将逐个学习如何自定义处理数据集、自定义网络模型、自定义损失函数、自定义优化器、自定义模型训练和自定义评价标准。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mindspore",
   "language": "python",
   "name": "mindvision"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
